<!doctype html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>MyBatis 异常处理完全指南</title>
    <link href="https://cdn.staticfile.org/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link href="https://cdn.staticfile.org/tailwindcss/2.2.19/tailwind.min.css" rel="stylesheet">
    <link href="https://fonts.googleapis.com/css2?family=Noto+Serif+SC:wght@400;500;600;700&family=Noto+Sans+SC:wght@300;400;500;700&display=swap" rel="stylesheet">
    <script src="https://cdn.jsdelivr.net/npm/mermaid@latest/dist/mermaid.min.js"></script>
    <style>
        body {
            font-family: 'Noto Sans SC', Tahoma, Arial, Roboto, "Droid Sans", "Helvetica Neue", "Droid Sans Fallback", "Heiti SC", "Hiragino Sans GB", Simsun, sans-serif;
        }
        .serif-font {
            font-family: 'Noto Serif SC', serif;
        }
        .gradient-text {
            background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            background-clip: text;
        }
        .card-hover {
            transition: all 0.3s ease;
        }
        .card-hover:hover {
            transform: translateY(-4px);
            box-shadow: 0 20px 40px rgba(0,0,0,0.1);
        }
        .error-card {
            background: linear-gradient(135deg, #ffeef8 0%, #fff5f5 100%);
            border-left: 4px solid #ef4444;
        }
        .solution-card {
            background: linear-gradient(135deg, #f0fdf4 0%, #f7fee7 100%);
            border-left: 4px solid #22c55e;
        }
        .code-block {
            background: #1e293b;
            color: #e2e8f0;
            border-radius: 8px;
            padding: 1rem;
            overflow-x: auto;
        }
        .mermaid {
            display: flex;
            justify-content: center;
            margin: 2rem 0;
        }
        .floating-icon {
            animation: float 3s ease-in-out infinite;
        }
        @keyframes float {
            0%, 100% { transform: translateY(0px); }
            50% { transform: translateY(-10px); }
        }
        .section-divider {
            background: linear-gradient(to right, transparent, #e5e7eb, transparent);
            height: 1px;
            margin: 3rem 0;
        }
        .drop-cap {
            float: left;
            font-size: 4rem;
            line-height: 1;
            font-weight: 700;
            margin-right: 0.5rem;
            margin-top: 0.25rem;
            color: #6366f1;
        }
    </style>
</head>
<body class="bg-gray-50">
    <!-- Hero Section -->
    <section class="relative overflow-hidden bg-gradient-to-br from-indigo-600 via-purple-600 to-pink-500 text-white">
        <div class="absolute inset-0 bg-black opacity-20"></div>
        <div class="relative container mx-auto px-6 py-24">
            <div class="max-w-4xl mx-auto text-center">
                <div class="floating-icon inline-block mb-6">
                    <i class="fas fa-exclamation-triangle text-6xl opacity-80"></i>
                </div>
                <h1 class="text-5xl md:text-6xl font-bold mb-6 serif-font">
                    MyBatis 异常处理完全指南
                </h1>
                <p class="text-xl md:text-2xl opacity-90 leading-relaxed">
                    深入剖析常见异常，掌握解决方案，让你的开发之路更加顺畅
                </p>
            </div>
        </div>
        <div class="absolute bottom-0 left-0 right-0">
            <svg viewBox="0 0 1440 120" fill="none" xmlns="http://www.w3.org/2000/svg">
                <path d="M0 120L60 110C120 100 240 80 360 70C480 60 600 60 720 65C840 70 960 80 1080 85C1200 90 1320 90 1380 90L1440 90V120H1380C1320 120 1200 120 1080 120C960 120 840 120 720 120C600 120 480 120 360 120C240 120 120 120 60 120H0V120Z" fill="#f9fafb"/>
            </svg>
        </div>
    </section>

    <!-- 概览卡片 -->
    <section class="container mx-auto px-6 py-16">
        <div class="max-w-6xl mx-auto">
            <div class="text-center mb-12">
                <h2 class="text-3xl font-bold text-gray-800 mb-4">异常类型概览</h2>
                <p class="text-lg text-gray-600">快速定位你遇到的问题类型</p>
            </div>
            <div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
                <div class="card-hover bg-white rounded-xl shadow-lg p-6">
                    <div class="flex items-center mb-4">
                        <div class="w-12 h-12 bg-red-100 rounded-full flex items-center justify-center mr-4">
                            <i class="fas fa-box text-red-500 text-xl"></i>
                        </div>
                        <h3 class="text-xl font-semibold text-gray-800">结果集封装异常</h3>
                    </div>
                    <p class="text-gray-600">MyBatis 不知道如何封装查询结果</p>
                </div>
                <div class="card-hover bg-white rounded-xl shadow-lg p-6">
                    <div class="flex items-center mb-4">
                        <div class="w-12 h-12 bg-blue-100 rounded-full flex items-center justify-center mr-4">
                            <i class="fas fa-key text-blue-500 text-xl"></i>
                        </div>
                        <h3 class="text-xl font-semibold text-gray-800">主键自增异常</h3>
                    </div>
                    <p class="text-gray-600">主键值未设置导致的插入失败</p>
                </div>
                <div class="card-hover bg-white rounded-xl shadow-lg p-6">
                    <div class="flex items-center mb-4">
                        <div class="w-12 h-12 bg-green-100 rounded-full flex items-center justify-center mr-4">
                            <i class="fas fa-database text-green-500 text-xl"></i>
                        </div>
                        <h3 class="text-xl font-semibold text-gray-800">字段不存在异常</h3>
                    </div>
                    <p class="text-gray-600">访问数据库中不存在的字段</p>
                </div>
                <div class="card-hover bg-white rounded-xl shadow-lg p-6">
                    <div class="flex items-center mb-4">
                        <div class="w-12 h-12 bg-yellow-100 rounded-full flex items-center justify-center mr-4">
                            <i class="fas fa-ruler text-yellow-500 text-xl"></i>
                        </div>
                        <h3 class="text-xl font-semibold text-gray-800">字段长度异常</h3>
                    </div>
                    <p class="text-gray-600">数据长度超出字段定义范围</p>
                </div>
                <div class="card-hover bg-white rounded-xl shadow-lg p-6">
                    <div class="flex items-center mb-4">
                        <div class="w-12 h-12 bg-purple-100 rounded-full flex items-center justify-center mr-4">
                            <i class="fas fa-file-code text-purple-500 text-xl"></i>
                        </div>
                        <h3 class="text-xl font-semibold text-gray-800">Mapper 未注册</h3>
                    </div>
                    <p class="text-gray-600">配置文件中未指定 Mapper 文件</p>
                </div>
                <div class="card-hover bg-white rounded-xl shadow-lg p-6">
                    <div class="flex items-center mb-4">
                        <div class="w-12 h-12 bg-indigo-100 rounded-full flex items-center justify-center mr-4">
                            <i class="fas fa-search text-indigo-500 text-xl"></i>
                        </div>
                        <h3 class="text-xl font-semibold text-gray-800">参数未找到</h3>
                    </div>
                    <p class="text-gray-600">方法参数映射配置错误</p>
                </div>
            </div>
        </div>
    </section>

    <!-- 异常关系图 -->
    <section class="bg-white py-16">
        <div class="container mx-auto px-6">
            <div class="max-w-6xl mx-auto">
                <h2 class="text-3xl font-bold text-center text-gray-800 mb-12">异常关系图谱</h2>
                <div class="mermaid">
                    graph TD
                    A[MyBatis 异常体系] --> B[配置异常]
                    A --> C[运行时异常]
                    B --> D[Mapper未注册]
                    B --> E[resultType未设置]
                    C --> F[结果集封装异常]
                    C --> G[参数映射异常]
                    C --> H[数据库操作异常]
                    H --> I[主键自增异常]
                    H --> J[字段不存在]
                    H --> K[字段长度超限]
                    G --> L[参数未找到]
                    G --> M[返回多个值]
                    
                    style A fill:#6366f1,stroke:#4f46e5,color:#fff
                    style B fill:#f59e0b,stroke:#d97706,color:#fff
                    style C fill:#ef4444,stroke:#dc2626,color:#fff
                </div>
            </div>
        </div>
    </section>

    <!-- 详细异常解析 -->
    <section class="container mx-auto px-6 py-16">
        <div class="max-w-4xl mx-auto">
            <h2 class="text-4xl font-bold text-center text-gray-800 mb-16 serif-font">异常详解与解决方案</h2>
            
            <!-- 异常1：结果集封装异常 -->
            <div class="mb-16">
                <h3 class="text-2xl font-bold text-gray-800 mb-6 flex items-center">
                    <i class="fas fa-exclamation-circle text-red-500 mr-3"></i>
                    结果集封装异常
                </h3>
                <div class="error-card rounded-lg p-6 mb-6">
                    <h4 class="font-semibold text-gray-700 mb-3">异常表现</h4>
                    <img src="https://cdn.nlark.com/yuque/0/2021/png/21449790/1631516476940-dfcf0142-37af-4ff0-ba70-df68826186bd.png" 
                         class="w-full rounded-lg shadow-md mb-4" alt="结果集封装异常截图">
                    <p class="text-gray-600">
                        <span class="drop-cap serif-font">当</span>MyBatis 执行 SQL 语句后，获取到数据库返回的结果集，但不知道应该封装到哪个对象中时，就会抛出此异常。这通常发生在 select 标签缺少必要的结果映射配置时。
                    </p>
                </div>
                <div class="solution-card rounded-lg p-6">
                    <h4 class="font-semibold text-gray-700 mb-3">
                        <i class="fas fa-lightbulb text-green-500 mr-2"></i>解决方案
                    </h4>
                    <p class="text-gray-700 mb-3">为 select 标签配置 resultMap 或 resultType 属性：</p>
                    <div class="code-block">
                        <pre>&lt;select id="selectUser" resultType="com.example.User"&gt;
    SELECT * FROM users WHERE id = #{id}
&lt;/select&gt;</pre>
                    </div>
                </div>
            </div>

            <div class="section-divider"></div>

            <!-- 异常2：主键自增异常 -->
            <div class="mb-16">
                <h3 class="text-2xl font-bold text-gray-800 mb-6 flex items-center">
                    <i class="fas fa-exclamation-circle text-red-500 mr-3"></i>
                    主键自增异常
                </h3>
                <div class="error-card rounded-lg p-6 mb-6">
                    <h4 class="font-semibold text-gray-700 mb-3">异常表现</h4>
                    <img src="https://cdn.nlark.com/yuque/0/2021/png/21449790/1631517925669-f6a8470b-705a-4cf3-87a0-cde153b278df.png" 
                         class="w-full rounded-lg shadow-md mb-4" alt="主键自增异常截图">
                    <p class="text-gray-600">主键具有唯一性和非空性的特点。当插入数据时没有为主键设置值，且主键未配置自增，就会触发此异常。</p>
                </div>
                <div class="solution-card rounded-lg p-6">
                    <h4 class="font-semibold text-gray-700 mb-3">
                        <i class="fas fa-lightbulb text-green-500 mr-2"></i>解决方案
                    </h4>
                    <p class="text-gray-700 mb-3">配置主键自增：</p>
                    <div class="code-block mb-3">
                        <pre>&lt;insert id="insertUser" useGeneratedKeys